package com.chebaohui.iqs.mapper;

import java.util.List;

import org.apache.ibatis.annotations.DeleteProvider;
import org.apache.ibatis.annotations.InsertProvider;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.SelectProvider;
import org.apache.ibatis.annotations.UpdateProvider;
import org.springframework.transaction.annotation.Isolation;
import org.springframework.transaction.annotation.Propagation;
import org.springframework.transaction.annotation.Transactional;

import com.chebaohui.iqs.mapper.sql.Provider;

/**
 * ClassName: BaseMapper<br>
 * Description: 通用数据基本操作接口.<br>
 * Reason: 通过实体注解的形式组装sql语句 <br>
 * 复杂的sql由继承类自己实现 <br>
 * 
 * @author Sean
 * @date: 2017年3月7日 下午2:58:34
 * @version V1.0
 * @since JDK 1.8
 * @param <T>
 */
public interface BaseMapper<T> {

	/**
	 * 数据新增
	 * 
	 * @param t
	 * @return
	 */
	@Transactional(isolation = Isolation.DEFAULT, propagation = Propagation.REQUIRED)
	@InsertProvider(method = "insert", type = Provider.class)
	Integer insert(T t) throws Exception;

	/**
	 * 数据删除
	 * 
	 * @param t
	 * @return
	 * @throws Exception
	 */
	@Transactional(isolation = Isolation.DEFAULT, propagation = Propagation.REQUIRED)
	@DeleteProvider(method = "delete", type = Provider.class)
	Integer delect(T t) throws Exception;

	/**
	 * 数据更新
	 * 
	 * @param t
	 * @return
	 * @throws Exception
	 */
	@Transactional(isolation = Isolation.DEFAULT, propagation = Propagation.REQUIRED)
	@UpdateProvider(method = "update", type = Provider.class)
	Integer update(T t) throws Exception;

	/**
	 * 外键更新
	 * 
	 * @param t
	 * @return
	 * @throws Exception
	 */
	@Transactional(isolation = Isolation.DEFAULT, propagation = Propagation.REQUIRED)
	@UpdateProvider(method = "updateByForeign", type = Provider.class)
	Integer updateByForeign(T t) throws Exception;

	/**
	 * 数据非空禁用更新 <br>
	 * DBColumn(update=false)有效
	 * 
	 * @param t
	 * @param notNullDisable
	 * @return
	 * @throws Exception
	 */
	@Transactional(isolation = Isolation.DEFAULT, propagation = Propagation.REQUIRED)
	@UpdateProvider(method = "updateNullDisable", type = Provider.class)
	Integer updateNullDisable(T t) throws Exception;

	/**
	 * 根据主键查询一条记录
	 * 
	 * @param t
	 * @return
	 * @throws Exception
	 */
	@SelectProvider(method = "queryOne", type = Provider.class)
	T queryOne(T t) throws Exception;

	/**
	 * 根据条件查询数据集
	 * 
	 * @param t
	 * @return
	 * @throws Exception
	 */
	@SelectProvider(method = "queryAll", type = Provider.class)
	List<T> queryAll(T t) throws Exception;

	/**
	 * 根据条件获取主键集合
	 * 
	 * @param vehicle
	 * @return
	 * @throws Exception
	 */
	@SelectProvider(method = "queryIdByParam", type = Provider.class)
	List<String> queryIdByParam(T t) throws Exception;

	/**
	 * 根据条件获取主键集合
	 * 
	 * @param vehicle
	 * @return
	 * @throws Exception
	 */
	@SelectProvider(method = "queryLimit", type = Provider.class)
	List<T> queryLimit(@Param("T") T t, Integer start, Integer length) throws Exception;
}
